<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<script>
	var ctx = "${ctx}";
</script>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加图说</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
	<meta http-equiv="expires" content="Wed, 26 Feb 209908:21:57 GMT"> 
    <link href="${ctx}/static/css/bootstrap.min.css?v=${static_version}" rel="stylesheet" />
	<link href="${ctx}/static/css/font-awesome.min.css" rel="stylesheet" />
	<link href="${ctx}/static/css/animate.min.css?v=${static_version}" rel="stylesheet" />
	<link href="${ctx}/static/css/style.min.css?v=${static_version}" rel="stylesheet" />
	<link href="${ctx}/static/css/common.css?v=${static_version}" rel="stylesheet" />
	<link href="//at.alicdn.com/t/font_9x03jhokyws9vn29.css" rel="stylesheet">
	<!-- 插件样式  -->
	<link href="${ctx}/static/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet" />
	<link href="${ctx}/static/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
	<link href="${ctx}/static/css/plugins/markdown/bootstrap-markdown.min.css" rel="stylesheet" />
    
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content  animated fadeInRight">
	<div class="ibox float-e-margins">
	   <div class="ibox-title">
        <h5>添加图说<small></small></h5>
	  </div>
	   <div class="ibox-content">
		<form action="${ctx}/article/article_addorUpdate" method="POST"
			class="form form-horizontal" id="form-u_article-add"
			onsubmit="before_submit()">
			<input type="hidden" name="id" value="${article.id}" /><input
				type="hidden" id="article_type" name="article_type" value="2" />

			<%-- <div class="form-group">
				<label class="col-sm-2 control-label">自媒体：</label>
				<div id="cat_select_div" class="formControls col-xs-8 col-sm-5">
					<select name="wemediaid" class="form-control">
						<option value="-1">请选择自媒体</option>
						<c:forEach items="${wemedialist}" var="wemedia">
							<option
								<c:if test="${article.org_id==wemedia.id}">selected="selected"</c:if>
								value="${wemedia.id}">${wemedia.media_title}</option>
						</c:forEach>
					</select>
				</div>
			</div> --%>

			<div class="form-group">
				<label class="col-sm-2 control-label">标题：</label>
				<div class="formControls col-xs-8 col-sm-5">
					<input type="text" class="form-control" value="${article.title}"
						placeholder="" id="" name="title" datatype="*" nullmsg="不能为空">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">分类：</label>
				<div id="cat_select_div" class="formControls col-xs-8 col-sm-5">
					<div class="cat_select_div_1" style="margin-bottom: 35px;">
						<div class="formControls col-3">
							<select name="cate_id" class="form-control" datatype="n">
								<option value="">选择分类</option>
								<c:forEach items="${article_cates}" var="cate">
									<option
										<c:if test="${article.cate_id==cate.id}">selected="selected"</c:if>
										value="${cate.id}">${cate.cate_name}</option>
								</c:forEach>
							</select>
						</div>
					</div>
				</div>
			</div>


			<div class="form-group">
				<label class="col-sm-2 control-label">标签：</label>
				<div id="insert3" class="formControls col-xs-8 col-sm-5">
					<div style="line-height: 28px;">
						<c:forEach items="${article_labs}" var="label">
							${label.label_name}:
							<c:forEach items="${label.childLabel}" var="clabel">
								<input
									<c:if test="">checked="checked"</c:if>
									type="checkbox" name="label" value="${clabel.label_name}">&nbsp;${clabel.label_name}&nbsp;&nbsp;
							</c:forEach>
							<br />
						</c:forEach>
					</div>
				</div>
			</div>

			<div class="form-group">
				<input type="hidden" id="img1" name="img1" value="" /> <label
					class="col-sm-2 control-label">图说详情：</label>
				<div class="formControls col-xs-8 col-sm-5">
							<div class="col-sm-10">
		<div  class="col-sm-2 m-l-n"  >
							<a id="filePicker1"><i class="iconfont icon-plus1"></i></a>						
							<br/>尺寸：380px *380px<br/>格式：JPG						
						</div>
		</div>
				</div>
			</div>


			<!-- 图说详情 -->
			<ul id="fileList1" class="uploader-list">
				<c:forEach items="${article.article_resources}" var="resource">
					<li><div class="form-group">
							<label class="col-sm-2 control-label">图片：</label>
							<div class="formControls col-xs-8 col-sm-5">
								<img style="width: 190px; height: 190px;" src="${resource.img}"><input
									type="hidden" value="${resource.img}" name="resource_url">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">内容：</label>
							<div class="col-sm-8">
							<textarea name="resource_description" data-provide="markdown" rows="5" class="textarea"
						placeholder="说点什么...最少输入10个字符...最多输入200个字符" datatype="*0-200" dragonfly="true"
						nullmsg="备注不能为空！" onKeyUp="textarealength(this,200)">${resource.description}</textarea>
						<button onclick="deltushuo(this)">删除</button>
							</div>
						</div>
						<hr /></li>
				</c:forEach>
			</ul>


			<div class="form-group">
				<label class="col-sm-2 control-label"></label>
				<div class="formControls col-xs-8 col-sm-5">
					<button onClick="u_article_save_submit();"
						class="btn btn-primary radius" type="submit" onsubmit="return false"">保存并提交</button>

				</div>
			</div>
		</form>
	</div>
	</div>
	</div>
	</div>

<script src="${ctx}/static/js/jquery.min.js"></script>
	<script src="${ctx}/static/js/bootstrap.min.js"></script>

	<!-- 插件脚本 -->
	<script src="${ctx}/static/js/plugins/layer/layer.js"></script>	
	<script src="${ctx}/static/js/jquery.form.js"></script>
	<script src="${ctx}/static/js/plugins/webuploader/webuploader.min.js"></script>
	<script src="${ctx}/static/js/plugins/validate/jquery.validate.min.js"></script>
	<script src="${ctx}/static/js/Validform/5.3.2/Validform.min.js"></script>
	<script src="${ctx}/static/js/plugins/dataTables/jquery.dataTables.js"></script>
	<script src="${ctx}/static/js/plugins/dataTables/dataTables.bootstrap.js"></script>	
	<script type="text/javascript" src="${ctx}/static/js/plugins/markdown/markdown.js"></script>
    <script type="text/javascript" src="${ctx}/static/js/plugins/markdown/to-markdown.js"></script>
    <script type="text/javascript" src="${ctx}/static/js/plugins/markdown/bootstrap-markdown.js"></script>
    <script type="text/javascript" src="${ctx}/static/js/plugins/markdown/bootstrap-markdown.zh.js"></script>
    <script type="text/javascript" charset="utf-8"src="${ctx}/static/js/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8"src="${ctx}/static/js/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript">
	//var baseurl;
	function u_article_save_submit(){
		var status = ${member.verify_media};
		//alert(status);
		if( status == 1){
		$("#form-u_article-add").Validform({
			tiptype:2,
			ajaxPost:true,
			callback:function(form){
				var index = parent.layer.getFrameIndex(window.name);
				if (index){//关闭弹出层
					parent.$('.btn-refresh').click(); 
					parent.layer.close(index);
					layer.msg('操作失败', {icon:5,time:1000});
				}else{//单独的页面
					parent.$('.btn-refresh').click();
					layer.msg('操作成功', {icon:6,time:1000});
					location.href = "${ctx}/article/webarticlelist";
					
					}
			}
		});
	return true;
	}else{
		alert("您还不是认证的自媒体，无法进行该操作！");
		history.go(0); 
	}
}
		//初始化Ueditor
		$(function() {
	
			/*缩略图上传*/
			var $list = $('#fileList1'), ratio = window.devicePixelRatio || 1, thumbnailWidth = 100 * ratio, thumbnailHeight = 100 * ratio, uploader;

			uploader = WebUploader.create({
				auto : true,
				swf : 'lib/webuploader/0.1.5/Uploader.swf',
				server : '${ctx}/file/uploadPic',
				pick : '#filePicker1',
				accept : {
					title : 'Images',
					extensions : 'gif,jpg,jpeg,bmp,png',
					mimeTypes : 'image/jpg,image/jpeg,image/png'
				},
				formData : {
					foldername : ''
				}
			});

			uploader.on('fileQueued', function(file) {

			});

			uploader
					.on(
							'uploadSuccess',
							function(file, response) {

								var $li = $('<li><div class="form-group"><label class="col-sm-2 control-label">图片：</label>'
										+ '<div class="formControls col-xs-8 col-sm-5"><img style="width: 190px; height: 190px;"'
										+' src="'+response.datas+'"><input type="hidden" value="'+response.datas+'" name="resource_url"></div></div>'
										+ '<div class="form-group"><label class="col-sm-2 control-label">内容：</label><div class="formControls col-xs-8 col-sm-5">'
										+ '<textarea name="resource_description" style="resize: none; width: 460px; heigth: 150px;"></textarea><button onclick="deltushuo(this)">删除</button></div></div><hr/></li>');
								$list.append($li);
							});

			uploader.on('uploadError', function(file) {
				var $li = $('#' + file.id), $error = $li.find('div.error');
				if (!$error.length) {
					$error = $('<div class="error"></div>').appendTo($li);
				}

				$error.text('上传失败');
			});

			uploader.on('uploadComplete', function(file) {
				$('#' + file.id).find('.progress').remove();
			});

		});

		function before_submit() {
			if ($('#fileList1').children().length == 0) {
				return false;
			} else {
				return true;
			}
		}

		function deltushuo(obj) {
			$(obj).parent().parent().parent().remove();
		}
	</script>
</body>
</html>

